<?php
/**
 * 异常处理接管
 * @author xiejianwen@star-net.cn
 * @copyright © ktvme. All Rights Reserved.
 * @version $Id: ErrorHandle.php 391 2017-11-28 11:57:40Z chendanming $
 */

namespace error;

use Exception;
use think\exception\Handle;
use think\App;
use think\console\Output;
use think\Log;
use think\Response;

class ErrorHandle extends Handle {

    public function report(Exception $exception) {
        if(!$this->isIgnoreReport($exception)) {
            // 收集异常数据
            if(App::$debug) {
                $data = [
                    'file'    => $exception->getFile(),
                    'line'    => $exception->getLine(),
                    'message' => $this->getMessage($exception),
                    'code'    => $this->getCode($exception),
                ];
                $log  = json_encode($data);
            } else {
                $data = [
                    'file'    => $exception->getFile(),
                    'line'    => $exception->getLine(),
                    'code'    => $this->getCode($exception),
                    'message' => $this->getMessage($exception),
                ];
                $log  = json_encode($data);
            }

            Log::record(json_encode(['message' => $log]), 'elk_more_info', 'error_sys');
        }
    }
}